<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>分类: 技术教程 | 小小程序员</title><meta name="author" content="十一星野"><meta name="copyright" content="十一星野"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="ELK 日志收集系统进阶使用，本文主要讲解如何打造一个线上环境真实可用的日志收集系统。有了它，你就可以和去服务器上捞日志说再见了！  #ELK环境安装 ELK是指Elasticsearch、Kibana、Logstash这三种服务搭建的日志收集系统，具体搭建方式可以参考《SpringBoot应用整合ELK实现日志收集》。这里仅提供最新版本的docker-compose脚本和一些安装要点。  #d">
<meta property="og:type" content="article">
<meta property="og:title" content="你居然还去服务器上捞日志，搭个日志收集系统难道不香么！">
<meta property="og:url" content="https://ko25891wan.gitlab.io/2024/01/05b706ca527f.html">
<meta property="og:site_name" content="小小程序员">
<meta property="og:description" content="ELK 日志收集系统进阶使用，本文主要讲解如何打造一个线上环境真实可用的日志收集系统。有了它，你就可以和去服务器上捞日志说再见了！  #ELK环境安装 ELK是指Elasticsearch、Kibana、Logstash这三种服务搭建的日志收集系统，具体搭建方式可以参考《SpringBoot应用整合ELK实现日志收集》。这里仅提供最新版本的docker-compose脚本和一些安装要点。  #d">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png">
<meta property="article:published_time" content="2024-01-21T09:28:51.000Z">
<meta property="article:modified_time" content="2024-02-02T13:40:55.034Z">
<meta property="article:author" content="十一星野">
<meta property="article:tag" content="宅男,热血">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://ko25891wan.gitlab.io/2024/01/05b706ca527f.html"><link rel="preconnect" href="//fastly.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.5.1/css/all.min.css"><link rel="stylesheet" href="https://cdn.staticfile.org/fancyapps-ui/5.0.32/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: {"defaultEncoding":1,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.staticfile.org/egjs-infinitegrid/4.11.0/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '分类: 技术教程',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-02-02 21:40:55'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load',() => { preloader.endLoading() })

  if (false) {
    document.addEventListener('pjax:send', () => { preloader.initLoading() })
    document.addEventListener('pjax:complete', () => { preloader.endLoading() })
  }
})()</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">120</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-tools"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/md_editor/"><i class="fa-fw fas fa-pen"></i><span> MDEditor_my</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog-info"><a href="/" title="小小程序员"><span class="site-name">小小程序员</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-tools"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/md_editor/"><i class="fa-fw fas fa-pen"></i><span> MDEditor_my</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">你居然还去服务器上捞日志，搭个日志收集系统难道不香么！</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2024-01-21T09:28:51.000Z" title="发表于 2024-01-21 17:28:51">2024-01-21</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-02-02T13:40:55.034Z" title="更新于 2024-02-02 21:40:55">2024-02-02</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/">技术教程</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/mall/">mall</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/mall/%E5%8F%82%E8%80%83%E7%AF%87/">参考篇</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">4.2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>19分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="你居然还去服务器上捞日志，搭个日志收集系统难道不香么！"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><article class="post-content" id="article-container"><blockquote>
<p>ELK 日志收集系统进阶使用，本文主要讲解如何打造一个线上环境真实可用的日志收集系统。有了它，你就可以和去服务器上捞日志说再见了！</p>
</blockquote>
<h2 id="ELK环境安装"><a href="#ELK环境安装" class="headerlink" title="#ELK环境安装"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#elk%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85">#</a>ELK环境安装</h2><blockquote>
<p>ELK是指Elasticsearch、Kibana、Logstash这三种服务搭建的日志收集系统，具体搭建方式可以参考<a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_tiny_elk.html">《SpringBoot应用整合ELK实现日志收集》</a>。这里仅提供最新版本的docker-compose脚本和一些安装要点。</p>
</blockquote>
<h3 id="docker-compose脚本"><a href="#docker-compose脚本" class="headerlink" title="#docker-compose脚本"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#docker-compose%E8%84%9A%E6%9C%AC">#</a>docker-compose脚本</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line">version: &#x27;3&#x27;</span><br><span class="line">services:</span><br><span class="line">  elasticsearch:</span><br><span class="line">    image: elasticsearch:6.4.0</span><br><span class="line">    container_name: elasticsearch</span><br><span class="line">    environment:</span><br><span class="line">      - &quot;cluster.name=elasticsearch&quot; #设置集群名称为elasticsearch</span><br><span class="line">      - &quot;discovery.type=single-node&quot; #以单一节点模式启动</span><br><span class="line">      - &quot;ES_JAVA_OPTS=-Xms512m -Xmx512m&quot; #设置使用jvm内存大小</span><br><span class="line">      - TZ=Asia/Shanghai</span><br><span class="line">    volumes:</span><br><span class="line">      - /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins #插件文件挂载</span><br><span class="line">      - /mydata/elasticsearch/data:/usr/share/elasticsearch/data #数据文件挂载</span><br><span class="line">    ports:</span><br><span class="line">      - 9200:9200</span><br><span class="line">      - 9300:9300</span><br><span class="line">  kibana:</span><br><span class="line">    image: kibana:6.4.0</span><br><span class="line">    container_name: kibana</span><br><span class="line">    links:</span><br><span class="line">      - elasticsearch:es #可以用es这个域名访问elasticsearch服务</span><br><span class="line">    depends_on:</span><br><span class="line">      - elasticsearch #kibana在elasticsearch启动之后再启动</span><br><span class="line">    environment:</span><br><span class="line">      - &quot;elasticsearch.hosts=http://es:9200&quot; #设置访问elasticsearch的地址</span><br><span class="line">      - TZ=Asia/Shanghai</span><br><span class="line">    ports:</span><br><span class="line">      - 5601:5601</span><br><span class="line">  logstash:</span><br><span class="line">    image: logstash:6.4.0</span><br><span class="line">    container_name: logstash</span><br><span class="line">    environment:</span><br><span class="line">      - TZ=Asia/Shanghai</span><br><span class="line">    volumes:</span><br><span class="line">      - /mydata/logstash/logstash.conf:/usr/share/logstash/pipeline/logstash.conf #挂载logstash的配置文件</span><br><span class="line">    depends_on:</span><br><span class="line">      - elasticsearch #kibana在elasticsearch启动之后再启动</span><br><span class="line">    links:</span><br><span class="line">      - elasticsearch:es #可以用es这个域名访问elasticsearch服务</span><br><span class="line">    ports:</span><br><span class="line">      - 4560:4560</span><br><span class="line">      - 4561:4561</span><br><span class="line">      - 4562:4562</span><br><span class="line">      - 4563:4563</span><br></pre></td></tr></table></figure>

<h3 id="安装要点"><a href="#安装要点" class="headerlink" title="#安装要点"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#%E5%AE%89%E8%A3%85%E8%A6%81%E7%82%B9">#</a>安装要点</h3><ul>
<li>使用<code>docker-compose</code>命令运行所有服务：</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker-compose up -d</span><br></pre></td></tr></table></figure>

<ul>
<li>第一次启动可能会发现Elasticsearch<code>无法启动</code>，那是因为<code>/usr/share/elasticsearch/data</code>目录没有访问权限，只需要修改<code>/mydata/elasticsearch/dat</code>a目录的权限，再重新启动；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod 777 /mydata/elasticsearch/data/</span><br></pre></td></tr></table></figure>

<ul>
<li>Logstash需要安装<code>json_lines</code>插件。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">logstash-plugin install logstash-codec-json_lines</span><br></pre></td></tr></table></figure>

<h2 id="分场景收集日志"><a href="#分场景收集日志" class="headerlink" title="#分场景收集日志"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#%E5%88%86%E5%9C%BA%E6%99%AF%E6%94%B6%E9%9B%86%E6%97%A5%E5%BF%97">#</a>分场景收集日志</h2><blockquote>
<p>这里为了方便我们查看日志，提出一个分场景收集日志的概念，把日志分为以下四种。</p>
</blockquote>
<ul>
<li>调试日志：最全日志，包含了应用中所有<code>DEBUG</code>级别以上的日志，仅在开发、测试环境中开启收集；</li>
<li>错误日志：只包含应用中所有<code>ERROR</code>级别的日志，所有环境只都开启收集；</li>
<li>业务日志：在我们应用<code>对应包下</code>打印的日志，可用于查看我们自己在应用中打印的业务日志；</li>
<li>记录日志：每个接口的<code>访问记录</code>，可以用来查看接口执行效率，获取接口访问参数。</li>
</ul>
<h2 id="Logback配置详解"><a href="#Logback配置详解" class="headerlink" title="#Logback配置详解"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#logback%E9%85%8D%E7%BD%AE%E8%AF%A6%E8%A7%A3">#</a>Logback配置详解</h2><blockquote>
<p>要实现上面的分场景收集日志，主要通过Logback的配置来实现，我们先来了解下Logback的配置吧！</p>
</blockquote>
<h3 id="完全配置"><a href="#完全配置" class="headerlink" title="#完全配置"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#%E5%AE%8C%E5%85%A8%E9%85%8D%E7%BD%AE">#</a>完全配置</h3><blockquote>
<p>在SpringBoot中，如果我们想要自定义Logback的配置，需要自行编写<code>logback-spring.xml</code>文件，下面是我们这次要使用的完全配置。</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span><br><span class="line">&lt;!DOCTYPE configuration&gt;</span><br><span class="line">&lt;configuration&gt;</span><br><span class="line">    &lt;!--引用默认日志配置--&gt;</span><br><span class="line">    &lt;include resource=&quot;org/springframework/boot/logging/logback/defaults.xml&quot;/&gt;</span><br><span class="line">    &lt;!--使用默认的控制台日志输出实现--&gt;</span><br><span class="line">    &lt;include resource=&quot;org/springframework/boot/logging/logback/console-appender.xml&quot;/&gt;</span><br><span class="line">    &lt;!--应用名称--&gt;</span><br><span class="line">    &lt;springProperty scope=&quot;context&quot; name=&quot;APP_NAME&quot; source=&quot;spring.application.name&quot; defaultValue=&quot;springBoot&quot;/&gt;</span><br><span class="line">    &lt;!--日志文件保存路径--&gt;</span><br><span class="line">    &lt;property name=&quot;LOG_FILE_PATH&quot; value=&quot;$&#123;LOG_FILE:-$&#123;LOG_PATH:-$&#123;LOG_TEMP:-$&#123;java.io.tmpdir:-/tmp&#125;&#125;&#125;/logs&#125;&quot;/&gt;</span><br><span class="line">    &lt;!--LogStash访问host--&gt;</span><br><span class="line">    &lt;springProperty name=&quot;LOG_STASH_HOST&quot; scope=&quot;context&quot; source=&quot;logstash.host&quot; defaultValue=&quot;localhost&quot;/&gt;</span><br><span class="line"></span><br><span class="line">    &lt;!--DEBUG日志输出到文件--&gt;</span><br><span class="line">    &lt;appender name=&quot;FILE_DEBUG&quot;</span><br><span class="line">              class=&quot;ch.qos.logback.core.rolling.RollingFileAppender&quot;&gt;</span><br><span class="line">        &lt;!--输出DEBUG以上级别日志--&gt;</span><br><span class="line">        &lt;filter class=&quot;ch.qos.logback.classic.filter.ThresholdFilter&quot;&gt;</span><br><span class="line">            &lt;level&gt;DEBUG&lt;/level&gt;</span><br><span class="line">        &lt;/filter&gt;</span><br><span class="line">        &lt;encoder&gt;</span><br><span class="line">            &lt;!--设置为默认的文件日志格式--&gt;</span><br><span class="line">            &lt;pattern&gt;$&#123;FILE_LOG_PATTERN&#125;&lt;/pattern&gt;</span><br><span class="line">            &lt;charset&gt;UTF-8&lt;/charset&gt;</span><br><span class="line">        &lt;/encoder&gt;</span><br><span class="line">        &lt;rollingPolicy class=&quot;ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy&quot;&gt;</span><br><span class="line">            &lt;!--设置文件命名格式--&gt;</span><br><span class="line">            &lt;fileNamePattern&gt;$&#123;LOG_FILE_PATH&#125;/debug/$&#123;APP_NAME&#125;-%d&#123;yyyy-MM-dd&#125;-%i.log&lt;/fileNamePattern&gt;</span><br><span class="line">            &lt;!--设置日志文件大小，超过就重新生成文件，默认10M--&gt;</span><br><span class="line">            &lt;maxFileSize&gt;$&#123;LOG_FILE_MAX_SIZE:-10MB&#125;&lt;/maxFileSize&gt;</span><br><span class="line">            &lt;!--日志文件保留天数，默认30天--&gt;</span><br><span class="line">            &lt;maxHistory&gt;$&#123;LOG_FILE_MAX_HISTORY:-30&#125;&lt;/maxHistory&gt;</span><br><span class="line">        &lt;/rollingPolicy&gt;</span><br><span class="line">    &lt;/appender&gt;</span><br><span class="line"></span><br><span class="line">    &lt;!--ERROR日志输出到文件--&gt;</span><br><span class="line">    &lt;appender name=&quot;FILE_ERROR&quot;</span><br><span class="line">              class=&quot;ch.qos.logback.core.rolling.RollingFileAppender&quot;&gt;</span><br><span class="line">        &lt;!--只输出ERROR级别的日志--&gt;</span><br><span class="line">        &lt;filter class=&quot;ch.qos.logback.classic.filter.LevelFilter&quot;&gt;</span><br><span class="line">            &lt;level&gt;ERROR&lt;/level&gt;</span><br><span class="line">            &lt;onMatch&gt;ACCEPT&lt;/onMatch&gt;</span><br><span class="line">            &lt;onMismatch&gt;DENY&lt;/onMismatch&gt;</span><br><span class="line">        &lt;/filter&gt;</span><br><span class="line">        &lt;encoder&gt;</span><br><span class="line">            &lt;!--设置为默认的文件日志格式--&gt;</span><br><span class="line">            &lt;pattern&gt;$&#123;FILE_LOG_PATTERN&#125;&lt;/pattern&gt;</span><br><span class="line">            &lt;charset&gt;UTF-8&lt;/charset&gt;</span><br><span class="line">        &lt;/encoder&gt;</span><br><span class="line">        &lt;rollingPolicy class=&quot;ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy&quot;&gt;</span><br><span class="line">            &lt;!--设置文件命名格式--&gt;</span><br><span class="line">            &lt;fileNamePattern&gt;$&#123;LOG_FILE_PATH&#125;/error/$&#123;APP_NAME&#125;-%d&#123;yyyy-MM-dd&#125;-%i.log&lt;/fileNamePattern&gt;</span><br><span class="line">            &lt;!--设置日志文件大小，超过就重新生成文件，默认10M--&gt;</span><br><span class="line">            &lt;maxFileSize&gt;$&#123;LOG_FILE_MAX_SIZE:-10MB&#125;&lt;/maxFileSize&gt;</span><br><span class="line">            &lt;!--日志文件保留天数，默认30天--&gt;</span><br><span class="line">            &lt;maxHistory&gt;$&#123;LOG_FILE_MAX_HISTORY:-30&#125;&lt;/maxHistory&gt;</span><br><span class="line">        &lt;/rollingPolicy&gt;</span><br><span class="line">    &lt;/appender&gt;</span><br><span class="line"></span><br><span class="line">    &lt;!--DEBUG日志输出到LogStash--&gt;</span><br><span class="line">    &lt;appender name=&quot;LOG_STASH_DEBUG&quot; class=&quot;net.logstash.logback.appender.LogstashTcpSocketAppender&quot;&gt;</span><br><span class="line">        &lt;filter class=&quot;ch.qos.logback.classic.filter.ThresholdFilter&quot;&gt;</span><br><span class="line">            &lt;level&gt;DEBUG&lt;/level&gt;</span><br><span class="line">        &lt;/filter&gt;</span><br><span class="line">        &lt;destination&gt;$&#123;LOG_STASH_HOST&#125;:4560&lt;/destination&gt;</span><br><span class="line">        &lt;encoder charset=&quot;UTF-8&quot; class=&quot;net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder&quot;&gt;</span><br><span class="line">            &lt;providers&gt;</span><br><span class="line">                &lt;timestamp&gt;</span><br><span class="line">                    &lt;timeZone&gt;Asia/Shanghai&lt;/timeZone&gt;</span><br><span class="line">                &lt;/timestamp&gt;</span><br><span class="line">                &lt;!--自定义日志输出格式--&gt;</span><br><span class="line">                &lt;pattern&gt;</span><br><span class="line">                    &lt;pattern&gt;</span><br><span class="line">                        &#123;</span><br><span class="line">                        &quot;project&quot;: &quot;mall-tiny&quot;,</span><br><span class="line">                        &quot;level&quot;: &quot;%level&quot;,</span><br><span class="line">                        &quot;service&quot;: &quot;$&#123;APP_NAME:-&#125;&quot;,</span><br><span class="line">                        &quot;pid&quot;: &quot;$&#123;PID:-&#125;&quot;,</span><br><span class="line">                        &quot;thread&quot;: &quot;%thread&quot;,</span><br><span class="line">                        &quot;class&quot;: &quot;%logger&quot;,</span><br><span class="line">                        &quot;message&quot;: &quot;%message&quot;,</span><br><span class="line">                        &quot;stack_trace&quot;: &quot;%exception&#123;20&#125;&quot;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &lt;/pattern&gt;</span><br><span class="line">                &lt;/pattern&gt;</span><br><span class="line">            &lt;/providers&gt;</span><br><span class="line">        &lt;/encoder&gt;</span><br><span class="line">        &lt;!--当有多个LogStash服务时，设置访问策略为轮询--&gt;</span><br><span class="line">        &lt;connectionStrategy&gt;</span><br><span class="line">            &lt;roundRobin&gt;</span><br><span class="line">                &lt;connectionTTL&gt;5 minutes&lt;/connectionTTL&gt;</span><br><span class="line">            &lt;/roundRobin&gt;</span><br><span class="line">        &lt;/connectionStrategy&gt;</span><br><span class="line">    &lt;/appender&gt;</span><br><span class="line"></span><br><span class="line">    &lt;!--ERROR日志输出到LogStash--&gt;</span><br><span class="line">    &lt;appender name=&quot;LOG_STASH_ERROR&quot; class=&quot;net.logstash.logback.appender.LogstashTcpSocketAppender&quot;&gt;</span><br><span class="line">        &lt;filter class=&quot;ch.qos.logback.classic.filter.LevelFilter&quot;&gt;</span><br><span class="line">            &lt;level&gt;ERROR&lt;/level&gt;</span><br><span class="line">            &lt;onMatch&gt;ACCEPT&lt;/onMatch&gt;</span><br><span class="line">            &lt;onMismatch&gt;DENY&lt;/onMismatch&gt;</span><br><span class="line">        &lt;/filter&gt;</span><br><span class="line">        &lt;destination&gt;$&#123;LOG_STASH_HOST&#125;:4561&lt;/destination&gt;</span><br><span class="line">        &lt;encoder charset=&quot;UTF-8&quot; class=&quot;net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder&quot;&gt;</span><br><span class="line">            &lt;providers&gt;</span><br><span class="line">                &lt;timestamp&gt;</span><br><span class="line">                    &lt;timeZone&gt;Asia/Shanghai&lt;/timeZone&gt;</span><br><span class="line">                &lt;/timestamp&gt;</span><br><span class="line">                &lt;!--自定义日志输出格式--&gt;</span><br><span class="line">                &lt;pattern&gt;</span><br><span class="line">                    &lt;pattern&gt;</span><br><span class="line">                        &#123;</span><br><span class="line">                        &quot;project&quot;: &quot;mall-tiny&quot;,</span><br><span class="line">                        &quot;level&quot;: &quot;%level&quot;,</span><br><span class="line">                        &quot;service&quot;: &quot;$&#123;APP_NAME:-&#125;&quot;,</span><br><span class="line">                        &quot;pid&quot;: &quot;$&#123;PID:-&#125;&quot;,</span><br><span class="line">                        &quot;thread&quot;: &quot;%thread&quot;,</span><br><span class="line">                        &quot;class&quot;: &quot;%logger&quot;,</span><br><span class="line">                        &quot;message&quot;: &quot;%message&quot;,</span><br><span class="line">                        &quot;stack_trace&quot;: &quot;%exception&#123;20&#125;&quot;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &lt;/pattern&gt;</span><br><span class="line">                &lt;/pattern&gt;</span><br><span class="line">            &lt;/providers&gt;</span><br><span class="line">        &lt;/encoder&gt;</span><br><span class="line">        &lt;!--当有多个LogStash服务时，设置访问策略为轮询--&gt;</span><br><span class="line">        &lt;connectionStrategy&gt;</span><br><span class="line">            &lt;roundRobin&gt;</span><br><span class="line">                &lt;connectionTTL&gt;5 minutes&lt;/connectionTTL&gt;</span><br><span class="line">            &lt;/roundRobin&gt;</span><br><span class="line">        &lt;/connectionStrategy&gt;</span><br><span class="line">    &lt;/appender&gt;</span><br><span class="line"></span><br><span class="line">    &lt;!--业务日志输出到LogStash--&gt;</span><br><span class="line">    &lt;appender name=&quot;LOG_STASH_BUSINESS&quot; class=&quot;net.logstash.logback.appender.LogstashTcpSocketAppender&quot;&gt;</span><br><span class="line">        &lt;destination&gt;$&#123;LOG_STASH_HOST&#125;:4562&lt;/destination&gt;</span><br><span class="line">        &lt;encoder charset=&quot;UTF-8&quot; class=&quot;net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder&quot;&gt;</span><br><span class="line">            &lt;providers&gt;</span><br><span class="line">                &lt;timestamp&gt;</span><br><span class="line">                    &lt;timeZone&gt;Asia/Shanghai&lt;/timeZone&gt;</span><br><span class="line">                &lt;/timestamp&gt;</span><br><span class="line">                &lt;!--自定义日志输出格式--&gt;</span><br><span class="line">                &lt;pattern&gt;</span><br><span class="line">                    &lt;pattern&gt;</span><br><span class="line">                        &#123;</span><br><span class="line">                        &quot;project&quot;: &quot;mall-tiny&quot;,</span><br><span class="line">                        &quot;level&quot;: &quot;%level&quot;,</span><br><span class="line">                        &quot;service&quot;: &quot;$&#123;APP_NAME:-&#125;&quot;,</span><br><span class="line">                        &quot;pid&quot;: &quot;$&#123;PID:-&#125;&quot;,</span><br><span class="line">                        &quot;thread&quot;: &quot;%thread&quot;,</span><br><span class="line">                        &quot;class&quot;: &quot;%logger&quot;,</span><br><span class="line">                        &quot;message&quot;: &quot;%message&quot;,</span><br><span class="line">                        &quot;stack_trace&quot;: &quot;%exception&#123;20&#125;&quot;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &lt;/pattern&gt;</span><br><span class="line">                &lt;/pattern&gt;</span><br><span class="line">            &lt;/providers&gt;</span><br><span class="line">        &lt;/encoder&gt;</span><br><span class="line">        &lt;!--当有多个LogStash服务时，设置访问策略为轮询--&gt;</span><br><span class="line">        &lt;connectionStrategy&gt;</span><br><span class="line">            &lt;roundRobin&gt;</span><br><span class="line">                &lt;connectionTTL&gt;5 minutes&lt;/connectionTTL&gt;</span><br><span class="line">            &lt;/roundRobin&gt;</span><br><span class="line">        &lt;/connectionStrategy&gt;</span><br><span class="line">    &lt;/appender&gt;</span><br><span class="line"></span><br><span class="line">    &lt;!--接口访问记录日志输出到LogStash--&gt;</span><br><span class="line">    &lt;appender name=&quot;LOG_STASH_RECORD&quot; class=&quot;net.logstash.logback.appender.LogstashTcpSocketAppender&quot;&gt;</span><br><span class="line">        &lt;destination&gt;$&#123;LOG_STASH_HOST&#125;:4563&lt;/destination&gt;</span><br><span class="line">        &lt;encoder charset=&quot;UTF-8&quot; class=&quot;net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder&quot;&gt;</span><br><span class="line">            &lt;providers&gt;</span><br><span class="line">                &lt;timestamp&gt;</span><br><span class="line">                    &lt;timeZone&gt;Asia/Shanghai&lt;/timeZone&gt;</span><br><span class="line">                &lt;/timestamp&gt;</span><br><span class="line">                &lt;!--自定义日志输出格式--&gt;</span><br><span class="line">                &lt;pattern&gt;</span><br><span class="line">                    &lt;pattern&gt;</span><br><span class="line">                        &#123;</span><br><span class="line">                        &quot;project&quot;: &quot;mall-tiny&quot;,</span><br><span class="line">                        &quot;level&quot;: &quot;%level&quot;,</span><br><span class="line">                        &quot;service&quot;: &quot;$&#123;APP_NAME:-&#125;&quot;,</span><br><span class="line">                        &quot;class&quot;: &quot;%logger&quot;,</span><br><span class="line">                        &quot;message&quot;: &quot;%message&quot;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &lt;/pattern&gt;</span><br><span class="line">                &lt;/pattern&gt;</span><br><span class="line">            &lt;/providers&gt;</span><br><span class="line">        &lt;/encoder&gt;</span><br><span class="line">        &lt;!--当有多个LogStash服务时，设置访问策略为轮询--&gt;</span><br><span class="line">        &lt;connectionStrategy&gt;</span><br><span class="line">            &lt;roundRobin&gt;</span><br><span class="line">                &lt;connectionTTL&gt;5 minutes&lt;/connectionTTL&gt;</span><br><span class="line">            &lt;/roundRobin&gt;</span><br><span class="line">        &lt;/connectionStrategy&gt;</span><br><span class="line">    &lt;/appender&gt;</span><br><span class="line"></span><br><span class="line">    &lt;!--控制框架输出日志--&gt;</span><br><span class="line">    &lt;logger name=&quot;org.slf4j&quot; level=&quot;INFO&quot;/&gt;</span><br><span class="line">    &lt;logger name=&quot;springfox&quot; level=&quot;INFO&quot;/&gt;</span><br><span class="line">    &lt;logger name=&quot;io.swagger&quot; level=&quot;INFO&quot;/&gt;</span><br><span class="line">    &lt;logger name=&quot;org.springframework&quot; level=&quot;INFO&quot;/&gt;</span><br><span class="line">    &lt;logger name=&quot;org.hibernate.validator&quot; level=&quot;INFO&quot;/&gt;</span><br><span class="line"></span><br><span class="line">    &lt;root level=&quot;DEBUG&quot;&gt;</span><br><span class="line">        &lt;appender-ref ref=&quot;CONSOLE&quot;/&gt;</span><br><span class="line">        &lt;!--&lt;appender-ref ref=&quot;FILE_DEBUG&quot;/&gt;--&gt;</span><br><span class="line">        &lt;!--&lt;appender-ref ref=&quot;FILE_ERROR&quot;/&gt;--&gt;</span><br><span class="line">        &lt;appender-ref ref=&quot;LOG_STASH_DEBUG&quot;/&gt;</span><br><span class="line">        &lt;appender-ref ref=&quot;LOG_STASH_ERROR&quot;/&gt;</span><br><span class="line">    &lt;/root&gt;</span><br><span class="line"></span><br><span class="line">    &lt;logger name=&quot;com.macro.mall.tiny.component&quot; level=&quot;DEBUG&quot;&gt;</span><br><span class="line">        &lt;appender-ref ref=&quot;LOG_STASH_RECORD&quot;/&gt;</span><br><span class="line">    &lt;/logger&gt;</span><br><span class="line"></span><br><span class="line">    &lt;logger name=&quot;com.macro.mall&quot; level=&quot;DEBUG&quot;&gt;</span><br><span class="line">        &lt;appender-ref ref=&quot;LOG_STASH_BUSINESS&quot;/&gt;</span><br><span class="line">    &lt;/logger&gt;</span><br><span class="line">&lt;/configuration&gt;</span><br></pre></td></tr></table></figure>

<h3 id="配置要点解析"><a href="#配置要点解析" class="headerlink" title="#配置要点解析"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#%E9%85%8D%E7%BD%AE%E8%A6%81%E7%82%B9%E8%A7%A3%E6%9E%90">#</a>配置要点解析</h3><h4 id="使用默认的日志配置"><a href="#使用默认的日志配置" class="headerlink" title="#使用默认的日志配置"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#%E4%BD%BF%E7%94%A8%E9%BB%98%E8%AE%A4%E7%9A%84%E6%97%A5%E5%BF%97%E9%85%8D%E7%BD%AE">#</a>使用默认的日志配置</h4><blockquote>
<p>一般我们不需要自定义控制台输出，可以采用默认配置，具体配置参考<code>console-appender.xml</code>，该文件在<code>spring-boot-$&#123;version&#125;.jar</code>下面。</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;!--引用默认日志配置--&gt;</span><br><span class="line">&lt;include resource=&quot;org/springframework/boot/logging/logback/defaults.xml&quot;/&gt;</span><br><span class="line">&lt;!--使用默认的控制台日志输出实现--&gt;</span><br><span class="line">&lt;include resource=&quot;org/springframework/boot/logging/logback/console-appender.xml&quot;/&gt;</span><br></pre></td></tr></table></figure>

<h4 id="springProperty"><a href="#springProperty" class="headerlink" title="#springProperty"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#springproperty">#</a>springProperty</h4><blockquote>
<p>该标签可以从SpringBoot的配置文件中获取配置属性，比如说在不同环境下我们的Logstash服务地址是不一样的，我们就可以把该地址定义在<code>application.yml</code>来使用。</p>
</blockquote>
<p>例如在<code>application-dev.yml</code>中定义了这些属性：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">logstash:</span><br><span class="line">  host: localhost</span><br></pre></td></tr></table></figure>

<p>在<code>logback-spring.xml</code>中就可以直接这样使用：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;!--应用名称--&gt;</span><br><span class="line">&lt;springProperty scope=&quot;context&quot; name=&quot;APP_NAME&quot; source=&quot;spring.application.name&quot; defaultValue=&quot;springBoot&quot;/&gt;</span><br><span class="line">&lt;!--LogStash访问host--&gt;</span><br><span class="line">&lt;springProperty name=&quot;LOG_STASH_HOST&quot; scope=&quot;context&quot; source=&quot;logstash.host&quot; defaultValue=&quot;localhost&quot;/&gt;</span><br></pre></td></tr></table></figure>

<h4 id="filter"><a href="#filter" class="headerlink" title="#filter"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#filter">#</a>filter</h4><blockquote>
<p>在Logback中有两种不同的过滤器，用来过滤日志输出。</p>
</blockquote>
<p>ThresholdFilter：临界值过滤器，过滤掉低于指定临界值的日志，比如下面的配置将过滤掉所有低于INFO级别的日志。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;filter class=&quot;ch.qos.logback.classic.filter.ThresholdFilter&quot;&gt;</span><br><span class="line">    &lt;level&gt;INFO&lt;/level&gt;</span><br><span class="line">&lt;/filter&gt;</span><br></pre></td></tr></table></figure>

<p>LevelFilter：级别过滤器，根据日志级别进行过滤，比如下面的配置将过滤掉所有非ERROR级别的日志。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;filter class=&quot;ch.qos.logback.classic.filter.LevelFilter&quot;&gt;</span><br><span class="line">    &lt;level&gt;ERROR&lt;/level&gt;</span><br><span class="line">    &lt;onMatch&gt;ACCEPT&lt;/onMatch&gt;</span><br><span class="line">    &lt;onMismatch&gt;DENY&lt;/onMismatch&gt;</span><br><span class="line">&lt;/filter&gt;</span><br></pre></td></tr></table></figure>

<h4 id="appender"><a href="#appender" class="headerlink" title="#appender"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#appender">#</a>appender</h4><blockquote>
<p>Appender可以用来控制日志的输出形式，主要有下面三种。</p>
</blockquote>
<ul>
<li>ConsoleAppender：控制日志输出到控制台的形式，比如在<code>console-appender.xml</code>中定义的默认控制台输出。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;appender name=&quot;CONSOLE&quot; class=&quot;ch.qos.logback.core.ConsoleAppender&quot;&gt;</span><br><span class="line">	&lt;encoder&gt;</span><br><span class="line">		&lt;pattern&gt;$&#123;CONSOLE_LOG_PATTERN&#125;&lt;/pattern&gt;</span><br><span class="line">	&lt;/encoder&gt;</span><br><span class="line">&lt;/appender&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li>RollingFileAppender：控制日志输出到文件的形式，可以控制日志文件生成策略，比如文件名称格式、超过多大重新生成文件以及删除超过多少天的文件。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&lt;!--ERROR日志输出到文件--&gt;</span><br><span class="line">&lt;appender name=&quot;FILE_ERROR&quot;</span><br><span class="line">          class=&quot;ch.qos.logback.core.rolling.RollingFileAppender&quot;&gt;</span><br><span class="line">    &lt;rollingPolicy class=&quot;ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy&quot;&gt;</span><br><span class="line">        &lt;!--设置文件命名格式--&gt;</span><br><span class="line">        &lt;fileNamePattern&gt;$&#123;LOG_FILE_PATH&#125;/error/$&#123;APP_NAME&#125;-%d&#123;yyyy-MM-dd&#125;-%i.log&lt;/fileNamePattern&gt;</span><br><span class="line">        &lt;!--设置日志文件大小，超过就重新生成文件，默认10M--&gt;</span><br><span class="line">        &lt;maxFileSize&gt;$&#123;LOG_FILE_MAX_SIZE:-10MB&#125;&lt;/maxFileSize&gt;</span><br><span class="line">        &lt;!--日志文件保留天数，默认30天--&gt;</span><br><span class="line">        &lt;maxHistory&gt;$&#123;LOG_FILE_MAX_HISTORY:-30&#125;&lt;/maxHistory&gt;</span><br><span class="line">    &lt;/rollingPolicy&gt;</span><br><span class="line">&lt;/appender&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li>LogstashTcpSocketAppender：控制日志输出到Logstash的形式，可以用来配置Logstash的地址、访问策略以及日志的格式。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">&lt;!--ERROR日志输出到LogStash--&gt;</span><br><span class="line">&lt;appender name=&quot;LOG_STASH_ERROR&quot; class=&quot;net.logstash.logback.appender.LogstashTcpSocketAppender&quot;&gt;</span><br><span class="line">    &lt;destination&gt;$&#123;LOG_STASH_HOST&#125;:4561&lt;/destination&gt;</span><br><span class="line">    &lt;encoder charset=&quot;UTF-8&quot; class=&quot;net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder&quot;&gt;</span><br><span class="line">        &lt;providers&gt;</span><br><span class="line">            &lt;timestamp&gt;</span><br><span class="line">                &lt;timeZone&gt;Asia/Shanghai&lt;/timeZone&gt;</span><br><span class="line">            &lt;/timestamp&gt;</span><br><span class="line">            &lt;!--自定义日志输出格式--&gt;</span><br><span class="line">            &lt;pattern&gt;</span><br><span class="line">                &lt;pattern&gt;</span><br><span class="line">                    &#123;</span><br><span class="line">                    &quot;project&quot;: &quot;mall-tiny&quot;,</span><br><span class="line">                    &quot;level&quot;: &quot;%level&quot;,</span><br><span class="line">                    &quot;service&quot;: &quot;$&#123;APP_NAME:-&#125;&quot;,</span><br><span class="line">                    &quot;pid&quot;: &quot;$&#123;PID:-&#125;&quot;,</span><br><span class="line">                    &quot;thread&quot;: &quot;%thread&quot;,</span><br><span class="line">                    &quot;class&quot;: &quot;%logger&quot;,</span><br><span class="line">                    &quot;message&quot;: &quot;%message&quot;,</span><br><span class="line">                    &quot;stack_trace&quot;: &quot;%exception&#123;20&#125;&quot;</span><br><span class="line">                    &#125;</span><br><span class="line">                &lt;/pattern&gt;</span><br><span class="line">            &lt;/pattern&gt;</span><br><span class="line">        &lt;/providers&gt;</span><br><span class="line">    &lt;/encoder&gt;</span><br><span class="line">    &lt;!--当有多个LogStash服务时，设置访问策略为轮询--&gt;</span><br><span class="line">    &lt;connectionStrategy&gt;</span><br><span class="line">        &lt;roundRobin&gt;</span><br><span class="line">            &lt;connectionTTL&gt;5 minutes&lt;/connectionTTL&gt;</span><br><span class="line">        &lt;/roundRobin&gt;</span><br><span class="line">    &lt;/connectionStrategy&gt;</span><br><span class="line">&lt;/appender&gt;</span><br></pre></td></tr></table></figure>

<h4 id="logger"><a href="#logger" class="headerlink" title="#logger"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#logger">#</a>logger</h4><blockquote>
<p>只有配置到logger节点上的appender才会被使用，logger用于配置哪种条件下的日志被打印，root是一种特殊的appender，下面介绍下日志划分的条件。</p>
</blockquote>
<ul>
<li>调试日志：所有的DEBUG级别以上日志；</li>
<li>错误日志：所有的ERROR级别日志；</li>
<li>业务日志：<code>com.macro.mall</code>包下的所有DEBUG级别以上日志；</li>
<li>记录日志：<code>com.macro.mall.tiny.component.WebLogAspect</code>类下所有DEBUG级别以上日志，该类是统计接口访问信息的AOP切面类。</li>
</ul>
<h4 id="控制框架输出日志"><a href="#控制框架输出日志" class="headerlink" title="#控制框架输出日志"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#%E6%8E%A7%E5%88%B6%E6%A1%86%E6%9E%B6%E8%BE%93%E5%87%BA%E6%97%A5%E5%BF%97">#</a>控制框架输出日志</h4><blockquote>
<p>还有一些使用框架内部的日志，DEBUG级别的日志对我们并没有啥用处，都可以设置为了INFO以上级别。</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&lt;!--控制框架输出日志--&gt;</span><br><span class="line">&lt;logger name=&quot;org.slf4j&quot; level=&quot;INFO&quot;/&gt;</span><br><span class="line">&lt;logger name=&quot;springfox&quot; level=&quot;INFO&quot;/&gt;</span><br><span class="line">&lt;logger name=&quot;io.swagger&quot; level=&quot;INFO&quot;/&gt;</span><br><span class="line">&lt;logger name=&quot;org.springframework&quot; level=&quot;INFO&quot;/&gt;</span><br><span class="line">&lt;logger name=&quot;org.hibernate.validator&quot; level=&quot;INFO&quot;/&gt;</span><br></pre></td></tr></table></figure>

<h2 id="Logstash配置详解"><a href="#Logstash配置详解" class="headerlink" title="#Logstash配置详解"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#logstash%E9%85%8D%E7%BD%AE%E8%AF%A6%E8%A7%A3">#</a>Logstash配置详解</h2><blockquote>
<p>接下来我们需要配置下Logstash，让它可以分场景收集不同的日志，下面详细介绍下使用到的配置。</p>
</blockquote>
<h3 id="完全配置-1"><a href="#完全配置-1" class="headerlink" title="#完全配置"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#%E5%AE%8C%E5%85%A8%E9%85%8D%E7%BD%AE-1">#</a>完全配置</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">input &#123;</span><br><span class="line">  tcp &#123;</span><br><span class="line">    mode =&gt; &quot;server&quot;</span><br><span class="line">    host =&gt; &quot;0.0.0.0&quot;</span><br><span class="line">    port =&gt; 4560</span><br><span class="line">    codec =&gt; json_lines</span><br><span class="line">    type =&gt; &quot;debug&quot;</span><br><span class="line">  &#125;</span><br><span class="line">  tcp &#123;</span><br><span class="line">    mode =&gt; &quot;server&quot;</span><br><span class="line">    host =&gt; &quot;0.0.0.0&quot;</span><br><span class="line">    port =&gt; 4561</span><br><span class="line">    codec =&gt; json_lines</span><br><span class="line">    type =&gt; &quot;error&quot;</span><br><span class="line">  &#125;</span><br><span class="line">  tcp &#123;</span><br><span class="line">    mode =&gt; &quot;server&quot;</span><br><span class="line">    host =&gt; &quot;0.0.0.0&quot;</span><br><span class="line">    port =&gt; 4562</span><br><span class="line">    codec =&gt; json_lines</span><br><span class="line">    type =&gt; &quot;business&quot;</span><br><span class="line">  &#125;</span><br><span class="line">  tcp &#123;</span><br><span class="line">    mode =&gt; &quot;server&quot;</span><br><span class="line">    host =&gt; &quot;0.0.0.0&quot;</span><br><span class="line">    port =&gt; 4563</span><br><span class="line">    codec =&gt; json_lines</span><br><span class="line">    type =&gt; &quot;record&quot;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">filter&#123;</span><br><span class="line">  if [type] == &quot;record&quot; &#123;</span><br><span class="line">    mutate &#123;</span><br><span class="line">      remove_field =&gt; &quot;port&quot;</span><br><span class="line">      remove_field =&gt; &quot;host&quot;</span><br><span class="line">      remove_field =&gt; &quot;@version&quot;</span><br><span class="line">    &#125;</span><br><span class="line">    json &#123;</span><br><span class="line">      source =&gt; &quot;message&quot;</span><br><span class="line">      remove_field =&gt; [&quot;message&quot;]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">output &#123;</span><br><span class="line">  elasticsearch &#123;</span><br><span class="line">    hosts =&gt; [&quot;es:9200&quot;]</span><br><span class="line">    action =&gt; &quot;index&quot;</span><br><span class="line">    codec =&gt; json</span><br><span class="line">    index =&gt; &quot;mall-tiny-%&#123;type&#125;-%&#123;+YYYY.MM.dd&#125;&quot;</span><br><span class="line">    template_name =&gt; &quot;mall-tiny&quot;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="配置要点"><a href="#配置要点" class="headerlink" title="#配置要点"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#%E9%85%8D%E7%BD%AE%E8%A6%81%E7%82%B9">#</a>配置要点</h3><ul>
<li>input：使用不同端口收集不同类型的日志，从4560~4563开启四个端口；</li>
<li>filter：对于记录类型的日志，直接将JSON格式的message转化到source中去，便于搜索查看；</li>
<li>output：按类型、时间自定义索引格式。</li>
</ul>
<h2 id="SpringBoot配置"><a href="#SpringBoot配置" class="headerlink" title="#SpringBoot配置"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#springboot%E9%85%8D%E7%BD%AE">#</a>SpringBoot配置</h2><blockquote>
<p>在SpringBoot中的配置可以直接用来覆盖Logback中的配置，比如<code>logging.level.root</code>就可以覆盖<code>&lt;root&gt;</code>节点中的<code>level</code>配置。</p>
</blockquote>
<ul>
<li>开发环境配置：application-dev.yml</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">logstash:</span><br><span class="line">  host: localhost</span><br><span class="line">logging:</span><br><span class="line">  level:</span><br><span class="line">    root: debug</span><br></pre></td></tr></table></figure>

<ul>
<li>测试环境配置：application-test.yml</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">logstash:</span><br><span class="line">  host: 192.168.3.101</span><br><span class="line">logging:</span><br><span class="line">  level:</span><br><span class="line">    root: debug</span><br></pre></td></tr></table></figure>

<ul>
<li>生产环境配置：application-prod.yml</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">logstash:</span><br><span class="line">  host: logstash-prod</span><br><span class="line">logging:</span><br><span class="line">  level:</span><br><span class="line">    root: info</span><br></pre></td></tr></table></figure>

<h2 id="Kibana进阶使用"><a href="#Kibana进阶使用" class="headerlink" title="#Kibana进阶使用"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#kibana%E8%BF%9B%E9%98%B6%E4%BD%BF%E7%94%A8">#</a>Kibana进阶使用</h2><blockquote>
<p>进过上面ELK环境的搭建和配置以后，我们的日志收集系统终于可以用起来了，下面介绍下在Kibana中的使用技巧！</p>
</blockquote>
<ul>
<li>首先启动我们的测试Demo，然后通用调用接口（可以使用Swagger），产生一些日志信息；</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/elk_advance_01-75187d0d.png"></p>
<ul>
<li>调用完成后在<code>Management-&gt;Kibana-&gt;Index Patterns</code>中可以创建<code>Index Patterns</code>，Kibana服务访问地址：<a target="_blank" rel="noopener" href="http://192.168.3.101:5601/">http://192.168.3.101:5601</a></li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/elk_advance_02-959c21d0.png"></p>
<ul>
<li>创建完成后可以在<code>Discover</code>中查看所有日志，调试日志只需直接查看<code>mall-tiny-debug*</code>模式的日志即可；</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/elk_advance_03-2d18d82a.png"></p>
<ul>
<li>对于日志搜索，kibana有非常强大的提示功能，可以通过搜索栏右侧的<code>Options</code>按钮打开；</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/elk_advance_04-ffb145ea.png"></p>
<ul>
<li>记录日志只需直接查看<code>mall-tiny-record*</code>模式的日志即可，如果我们想要搜索uri为<code>/brand/listAll</code>的记录日志，只需在搜索栏中输入<code>uri : &quot;/brand/listAll&quot;</code>；</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/elk_advance_05-12b56f54.png"></p>
<ul>
<li>错误日志，只需直接查看<code>mall-tiny-error*</code>模式的日志即可；</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/elk_advance_06-108f95e7.png"></p>
<ul>
<li>业务日志，只需直接查看<code>mall-tiny-business*</code>模式的日志即可，这里我们可以查看一些SQL日志的输出；</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/elk_advance_07-a3370bc5.png"></p>
<ul>
<li>如果日志太大了，可以通过<code>Elasticsearch-&gt;Index Management</code>选择删除即可。</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/elk_advance_08-b6f3657f.png"></p>
<h2 id="项目源码地址"><a href="#项目源码地址" class="headerlink" title="#项目源码地址"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/mall_elk_advance.html#%E9%A1%B9%E7%9B%AE%E6%BA%90%E7%A0%81%E5%9C%B0%E5%9D%80">#</a>项目源码地址</h2><p><a target="_blank" rel="noopener" href="https://github.com/macrozheng/mall-learning/tree/master/mall-tiny-log">https://github.com/macrozheng/mall-learning/tree/master/mall-tiny-log</a></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://ko25891wan.gitlab.io">十一星野</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://ko25891wan.gitlab.io/2024/01/05b706ca527f.html">https://ko25891wan.gitlab.io/2024/01/05b706ca527f.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://ko25891wan.gitlab.io" target="_blank">小小程序员</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2024/01/5725e4a4a350.html" title="使用Docker Compose部署SpringBoot应用"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">使用Docker Compose部署SpringBoot应用</div></div></a></div><div class="next-post pull-right"><a href="/2024/01/ebe153280823.html" title="连RabbitMQ的5种核心消息模式都不懂，也敢说自己会用消息队列！"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">连RabbitMQ的5种核心消息模式都不懂，也敢说自己会用消息队列！</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">十一星野</div><div class="author-info__description">归途也还可爱</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">120</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io"><i class="fab fa-github"></i><span>关注我</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io" target="_blank" title="Gitlab"><i class="fab fa-gitlab" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:ko25891wan@outlook.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#ELK%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85"><span class="toc-number">1.</span> <span class="toc-text">ELK环境安装</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#docker-compose%E8%84%9A%E6%9C%AC"><span class="toc-number">1.1.</span> <span class="toc-text">docker-compose脚本</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%89%E8%A3%85%E8%A6%81%E7%82%B9"><span class="toc-number">1.2.</span> <span class="toc-text">安装要点</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%86%E5%9C%BA%E6%99%AF%E6%94%B6%E9%9B%86%E6%97%A5%E5%BF%97"><span class="toc-number">2.</span> <span class="toc-text">分场景收集日志</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Logback%E9%85%8D%E7%BD%AE%E8%AF%A6%E8%A7%A3"><span class="toc-number">3.</span> <span class="toc-text">Logback配置详解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%8C%E5%85%A8%E9%85%8D%E7%BD%AE"><span class="toc-number">3.1.</span> <span class="toc-text">完全配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE%E8%A6%81%E7%82%B9%E8%A7%A3%E6%9E%90"><span class="toc-number">3.2.</span> <span class="toc-text">配置要点解析</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8%E9%BB%98%E8%AE%A4%E7%9A%84%E6%97%A5%E5%BF%97%E9%85%8D%E7%BD%AE"><span class="toc-number">3.2.1.</span> <span class="toc-text">使用默认的日志配置</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#springProperty"><span class="toc-number">3.2.2.</span> <span class="toc-text">springProperty</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#filter"><span class="toc-number">3.2.3.</span> <span class="toc-text">filter</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#appender"><span class="toc-number">3.2.4.</span> <span class="toc-text">appender</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#logger"><span class="toc-number">3.2.5.</span> <span class="toc-text">logger</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8E%A7%E5%88%B6%E6%A1%86%E6%9E%B6%E8%BE%93%E5%87%BA%E6%97%A5%E5%BF%97"><span class="toc-number">3.2.6.</span> <span class="toc-text">控制框架输出日志</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Logstash%E9%85%8D%E7%BD%AE%E8%AF%A6%E8%A7%A3"><span class="toc-number">4.</span> <span class="toc-text">Logstash配置详解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%8C%E5%85%A8%E9%85%8D%E7%BD%AE-1"><span class="toc-number">4.1.</span> <span class="toc-text">完全配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE%E8%A6%81%E7%82%B9"><span class="toc-number">4.2.</span> <span class="toc-text">配置要点</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#SpringBoot%E9%85%8D%E7%BD%AE"><span class="toc-number">5.</span> <span class="toc-text">SpringBoot配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Kibana%E8%BF%9B%E9%98%B6%E4%BD%BF%E7%94%A8"><span class="toc-number">6.</span> <span class="toc-text">Kibana进阶使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B9%E7%9B%AE%E6%BA%90%E7%A0%81%E5%9C%B0%E5%9D%80"><span class="toc-number">7.</span> <span class="toc-text">项目源码地址</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/02/c60470b9a892.html" title="Java集合使用注意事项总结">Java集合使用注意事项总结</a><time datetime="2024-02-03T04:58:22.000Z" title="发表于 2024-02-03 12:58:22">2024-02-03</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/02/81fb7a201f29.html" title="无题">无题</a><time datetime="2024-02-03T03:15:31.812Z" title="发表于 2024-02-03 11:15:31">2024-02-03</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/5737c1ec69a9.html" title="Wed Jan 17 2024 00:00:00 GMT+0800 (中国标准时间)">Wed Jan 17 2024 00:00:00 GMT+0800 (中国标准时间)</a><time datetime="2024-01-31T06:56:16.000Z" title="发表于 2024-01-31 14:56:16">2024-01-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/f510db7d2f19.html" title="Spring常见面试题总结">Spring常见面试题总结</a><time datetime="2024-01-31T06:55:58.000Z" title="发表于 2024-01-31 14:55:58">2024-01-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/9be065e9f288.html" title="redis 面试">redis 面试</a><time datetime="2024-01-31T06:55:55.000Z" title="发表于 2024-01-31 14:55:55">2024-01-31</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2023 - 2024 By 十一星野</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.staticfile.org/fancyapps-ui/5.0.32/fancybox/fancybox.umd.min.js"></script><script src="https://cdn.staticfile.org/instant.page/5.2.0/instantpage.min.js" type="module"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div></body></html>